//切换省份更新市
function changeProvince(obj) {
	//切换省份时将分页设置为第1页
	var pageNumber = 1;
	//获取卡槽类型
	var selectedCardTrough = $("#hidden_selectedCardTrough").val();
	//省
	var province = $(obj).val();
	//市
	var cityOptions = '';
	$("#selectEndNum").find('input[name="'+ province +'"]').each(function(idx){
		if(idx == 0) {
			$("#selectedCity").attr("value", $(this).val());
		}
		cityOptions += '<option value="'+ $(this).val() +'">'+ $(this).val() +'</option>';
	});
	$("#secondCity").empty().append(cityOptions);
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, selectedCardTrough:selectedCardTrough, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			if($(data).find('p').length<40){
				$("#pullUp").remove();
			}
			$("#phoneNumInfo").empty().append(data);
		}
	});
	myScroll.refresh();	
}

//切换城市事件
function changeCity(obj) {
	$("#selectedCity").attr("value", $(obj).val());
	//切换城市时将分页设置为第1页
	var pageNumber = 1;
	//获取卡槽类型
	var selectedCardTrough = $("#hidden_selectedCardTrough").val();
	//获取城市
	var city = $(obj).val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, selectedCardTrough:selectedCardTrough, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			if($(data).find('p').length<40){
				$("#pullUp").remove();
			}
			$("#phoneNumInfo").empty().append(data);
		}
	});
	myScroll.refresh();	
}

//号码排序
function orderNum() {
	//获取当前页数
	var pageNumber = $(".pageNumber-hidden").attr("value");
	var pageSize = 20;
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取价格当前排序类型
	var priceOrderType = $("#priceOrder").attr("name");
	
	var orderType = '';
	if($("#numOrder").hasClass("zm_cn_sorta")) {
		$("#numOrder").removeClass("zm_cn_sorta").addClass("zm_cn_sort");
		$("#numOrder").attr("name", "numDefaultDesc");
		orderType += 'numAsc';
	}else{
		$("#numOrder").removeClass("zm_cn_sort").addClass("zm_cn_sorta");
		orderType += 'numDesc';
		$("#numOrder").attr("name", "numDefaultAsc");
	}
	//获取号码当前排序类型
	var numOrderType = $("#numOrder").attr("name");
	//alert("numOrderType:"+numOrderType+" priceDefaultType:"+priceOrderType);

	$.ajax({
		url: "orderByNumberAndPrice.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			if($(data).find('p').length<40){
				$("#pullDown").remove();
			}
			$("#phoneNumInfo").empty().append(data);
		}
	});
	myScroll.refresh();	
}
//价格排序
function orderPrice() {
	var pageNumber = 1;
	var pageSize = 20;
	//获取卡槽类型
	var selectedCardTrough = $("#hidden_selectedCardTrough").val();
	//alert(selectedCardTrough);
	//获取城市
	var selectedCity = $("#selectedCity").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//靓号规则
	var prettyNumRule = $("#hidden_selectedPrettyNum").val();
	//获取号码当前排序类型
	var numDefaultType = $("#numOrder").attr("name");
	//alert("selectedCity:"+selectedCity+",startNum:"+startNum+",numDefaultType:"+numDefaultType);
	var orderType = '';
	if($("#priceOrder").hasClass("zm_cn_sorta")) {
		$("#priceOrder").removeClass("zm_cn_sorta").addClass("zm_cn_sort");
		$("#priceOrder").attr("name", "priceDefaultAsc");
		orderType += 'priceDefaultAsc';
	}else{
		$("#priceOrder").removeClass("zm_cn_sort").addClass("zm_cn_sorta");
		$("#priceOrder").attr("name", "priceDefaultDesc");
		orderType += 'priceDefaultDesc';
	}
	//alert("priceOrderType:"+orderType);
	$.ajax({
		url: "orderByNumberAndPrice.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, selectedCardTrough:selectedCardTrough, cityName:selectedCity, startNum:startNum, rule:prettyNumRule, numOrderType:numDefaultType, priceOrderType:orderType},
		dataType: "html",
		cache: false,
		async: false,
		success: function(data) {
			if($(data).find('p').length<40){
				$("#pullUp").remove();
			}
			$("#phoneNumInfo").empty().append(data);
		}
	});
	myScroll.refresh();	
}

//切换号段事件
function changeNum(obj) {
	$(".zm_inputText_none").attr("value", "");
	$("#selectedNum").attr("value", $(obj).val());
	//切换号段时将分页设置为第1页
	var pageNumber = 1;
	//获取卡槽类型
	var selectedCardTrough = $("#hidden_selectedCardTrough").val();
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, selectedCardTrough:selectedCardTrough, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			if($(data).find('p').length<40){
				$("#pullUp").remove();
			}
			$("#phoneNumInfo").empty().append(data);
		}
	});
	myScroll.refresh();	
}

//搜索4位尾号
function searchEndNum() {
	var regx = /^\d{4}$/;
	//获取4位尾号
	var endNum = $(".zm_inputText_none").val();
	if(endNum != ""){
		if(!regx.test(endNum)){
			$.message("error", "请输入4位数字!");
			return;
		}
	}
	$("#hidden_selectedPrettyNum").attr("value", "");
	//切换号段时将分页设置为第1页
	var pageNumber = 1;
	//获取卡槽类型
	var selectedCardTrough = $("#hidden_selectedCardTrough").val();
	//获取城市
	var city = $("#selectedCity").val();
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = "";
	var pageSize = 20;
	
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, selectedCardTrough:selectedCardTrough, cityName:city, endNum:endNum, startNum:startNum, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "HTML",
		cache: false,
		success: function(data) {
			if(($("#prettyNumFeature").find("option").text() == "尾号规则") == false){
				$("#prettyNumFeature").find("option").eq(0).attr("selected", "selected");
			}
			if($(data).find('p').length<40){
				$("#pullUp").remove();
			}
			$("#phoneNumInfo").empty().append(data);
		}
	});
	myScroll.refresh();	
}

//选择号码
function selectedPhoneNum(obj) {
	$(".zm_num_info").find("li").removeClass("on");
	$(obj).addClass("on");
	//所选号码
	var selectedPhoneNum = $(obj).find("p.zm_theNum").html();
	$("#hidden_selectedPhoneNum").attr("value", selectedPhoneNum);
}

//确定选号
function submitSelectedPhoneNum() {
	//alert($("#hidden_feeIllustrate").val());
	var selectedPhoneNum = $("#hidden_selectedPhoneNum").val();
	var selectedCardTrough = $("#hidden_selectedCardTrough").val();
	var hostName = $("#hidden_hostName").val();
	var cardId = $("#hidden_cardId").val();
	var cardTrough = $("#hidden_cardTrough").val();
	var isOpenCallsDisplay = $("#hidden_feeIllustrate").val();
	//商品ID
	var productId = $("#hidden_productId").val();
	hostName = encodeURI(hostName);
	hostName = encodeURI(hostName);
	if(isOpenCallsDisplay == ""){
		isOpenCallsDisplay = true;
	}
	//alert(isOpenCallsDisplay);
	window.location.href = "submitSelectedPhoneNum.jhtml?productId="+productId+"&selectedPhoneNum=" + selectedPhoneNum + "&selectedCardTrough="+selectedCardTrough+"&hostName="+ hostName +"&cardId="+ cardId +"&cardTrough="+ cardTrough +"&isOpenCallsDisplay="+ isOpenCallsDisplay +"";
}

//切换靓号规则
function  changePrettyNumFeature(obj) {
	//切换靓号规则时将分页设置为第1页
	var pageNumber = 1;
	//获取卡槽类型
	var selectedCardTrough = $("#hidden_selectedCardTrough").val();
	//获取城市
	var city = $("#selectedCity").val();
	//获取4位尾号
	var endNum = "";
	$("#inputEndNum").attr("value", "");
	//获取号段
	var startNum = $("#selectedNum").val();
	//获取所选靓号规则
	var prettyNumRule = $(obj).val();
	$("#hidden_selectedPrettyNum").attr("value", prettyNumRule);
	//获取号码、价格排序类型
	var numOrderType = $("#numOrder").attr("name");
	var priceOrderType = $("#priceOrder").attr("name");
	var pageSize = 20;
	$.ajax({
		url: "selectPhoneNumByPage.jhtml",
		type: "POST",
		data: {pageNumber: pageNumber, pageSize:pageSize, selectedCardTrough:selectedCardTrough, cityName:city, endNum:endNum, startNum:startNum, rule:prettyNumRule, numOrderType:numOrderType, priceOrderType:priceOrderType},
		dataType: "html",
		cache: false,
		async: false,
		success: function(data) {
			if($(data).find('p').length<40){
				$("#pullUp").remove();
				//$("#pullDown").remove();
			}
			$("#phoneNumInfo").empty().append(data);
			myScroll.refresh();	
		}
	});
}
//查询资费说明
function findFeeIllustrate() {
	//获取卡槽类型
	var selectedCardTrough = $("#hidden_selectedCardTrough").attr("value");
	var hostName = $("#hidden_hostName").val();
	var cardId = $("#hidden_cardId").val();
	var cardTrough = $("#hidden_cardTrough").val();
	//是否开通来电显示
	var defaultCallsDisplay = $("#hidden_feeIllustrate").attr("value");
	//商品ID
	var productId = $("#hidden_productId").attr("value");
	hostName = encodeURI(hostName);
	hostName = encodeURI(hostName);
	if(defaultCallsDisplay == ""){
		defaultCallsDisplay = true;
	}
	//alert(defaultCallsDisplay+","+selectedCardTrough);
	//所在页面，为了在资费页面点返回时回到选号码页面
	var currentLocation = "chooseNum";
	window.location.href = "feeIllustrate.jhtml?productId="+productId+"&hostName="+ hostName +"&cardId="+ cardId +"&cardTrough="+ cardTrough +"&defaultCallsDisplay="+ defaultCallsDisplay +"&selectedCardTrough="+selectedCardTrough+"&currentLocation="+ currentLocation +"";
}





